package com.example.qjia.model;

import android.util.Log;

import com.example.qjia.Listener.LoadStudentMessageListener;
import com.example.qjia.data.StudentMessage;
import com.example.qjia.data.romotedata.ResponseData;
import com.example.qjia.data.romotedata.Student;
import com.example.qjia.util.retrofit.RetrofitNet;

import rx.Observer;

/**
 * Created by ying_xiang on 2016/8/15.
 */
public class LoadStudentMessageModelImp implements LoadStudentMessageModel {
    @Override
    public void loadStudentMessage(final LoadStudentMessageListener loadStudentMessageListener) {

        /*Student studentMessage=new Student();
        studentMessage.setName("超级逗逼迪");
        studentMessage.setMclass("IOT");
        studentMessage.setPhone("110");
        studentMessage.setMajor("物联网");
        studentMessage.setEmail("fens_gogo@163.com");
        studentMessage.setAcademy("信息学院");
        studentMessage.setStudentId("3130758155");

        loadStudentMessageListener.loadStudentMessageSeccess(studentMessage);*/
        new RetrofitNet().getStudentById(new Observer<ResponseData<Student>>() {
            @Override
            public void onCompleted() {
                //完成
                System.out.println("finish");
            }

            @Override
            public void onError(Throwable e) {
                //异常
                System.out.println("error");
                Log.e("MAIN2",e.getLocalizedMessage()+"--"+e.getMessage());
            }

            @Override
            public void onNext(ResponseData<Student> baseBean) {
                //成功
                ResponseData  p=baseBean;
                System.out.println(p.getCode()+"--"+p.getMsg());
                if(p.getCode()==0) {            //表示提交成功

                    Student student=(Student)p.getData();

                    System.out.println(p.getCode() + "--" + p.toString());
                    loadStudentMessageListener.loadStudentMessageSeccess(student);
                }else{
                    loadStudentMessageListener.loadFailed();
                }

            }
        });

    }
}
